package com.rxyb.authority.gateway.controller;


import com.rxyb.authority.gateway.dto.user.*;
import com.rxyb.authority.service.OpsAuthorityUserService;
import com.rxyb.core.respone.R;
import com.rxyb.security.annotation.Inner;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author DUYH
 * @since 2020-05-29
 */
@RestController
@RequestMapping("/user")
public class OpsAuthorityUserController {

    @Autowired
    private OpsAuthorityUserService opsAuthorityUserService;

    /**
     * 登陆
     *
     * @author duyh
     */
    @Inner
    @PostMapping(value = "login", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public R<LoginRsp> login(@Validated @RequestBody LoginReq loginReq) {
        return opsAuthorityUserService.login(loginReq);
    }

    /**
     * 创建
     *
     * @author duyh
     */
    @PostMapping(value = "create", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public R<CreateUserRsp> create(@Validated @RequestBody CreateUserReq createUserReq) {
        return opsAuthorityUserService.create(createUserReq);
    }

    /**
     * 删除
     *
     * @author duyh
     */
    @PostMapping(value = "delete", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public R<DeleteUserRsp> delete(@Validated @RequestBody DeleteUserReq deleteUserReq) {
        return opsAuthorityUserService.remove(deleteUserReq);
    }

    /**
     * 修改
     *
     * @author duyh
     */
    @PostMapping(value = "update", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public R<UpdateUserRsp> update(@Validated @RequestBody UpdateUserReq updateUserReq) {
        return opsAuthorityUserService.updateById(updateUserReq);
    }

    /**
     * 改密
     *
     * @author duyh
     */
    @PostMapping(value = "updatePwd", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public R<UpdatePwdRsp> updatePwd(@Validated @RequestBody UpdatePwdReq updatePwdReq) {
        return opsAuthorityUserService.updatePwd(updatePwdReq);
    }

    /**
     * 详情
     *
     * @author duyh
     */
    @PostMapping(value = "query", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public R<GetUserInfoRsp> query(@Validated @RequestBody GetUserInfoReq getUserInfoReq) {
        return opsAuthorityUserService.query(getUserInfoReq);
    }

    /**
     * 列表
     *
     * @author duyh
     */
    @PostMapping(value = "list", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public R<GetUserListRsp> list(@Validated @RequestBody GetUserListReq getUserListReq) {
        return opsAuthorityUserService.list(getUserListReq);
    }
}
